 
 
<!DOCTYPE html>
<html class="site-demo-overflow">
<head>
<meta charset="utf-8">
<title> 颜色选择器- 在线演示 - Layui</title>
<meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black"> 
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">
  <script>
  ;!function(){self!==parent&&(location.href="//www.baidu.com/")}();
  </script>
  <link rel="stylesheet" href="../layui/dist/css/layui.css" media="all">
  <link rel="stylesheet" href="../static/css/global.css" media="all">
<style>
</style>
</head>
<body>
<div class="layui-layout layui-layout-admin">
  

<div class="layui-header header header-demo" autumn="">
  <div class="layui-fluid">
    <a class="logo" href="../index.html">
      <img src="../static/images/layui/logo.png" alt="layui">
    </a>
    <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
    <div class="layui-hide-xs site-notice"></div>
    
    <ul class="layui-nav" id="LAY_NAV_TOP">
      <li class="layui-nav-item ">
        <a href="../doc/index.html">文档</a> 
      </li>
      <li class="layui-nav-item layui-this">
        <a href="index.html">示例</a>
      </li>
      
      <li class="layui-nav-item">
        <a href="javascript:;">
          <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
          周边
        </a>
        <dl class="layui-nav-child layui-nav-child-c">  
          <dd class="layui-hide-sm layui-show-xs" lay-unselect="">
            <a href="javascript:window.open('https://gitee.com/sentsin/layui/issues');" target="_blank" rel="nofollow">问题反馈</a>
            <hr>
          </dd>
          
          <dd lay-unselect=""><a href="../alone.html" target="_blank" lay-unselect="">独立组件</a></dd>
          <dd lay-unselect=""><a href="../extend/index.html" target="_blank">扩展组件</a></dd>
        </dl>
      </li>
      
      <li class="layui-nav-item layui-hide-xs">
        <a href="javascript:window.open('https://gitee.com/sentsin/layui/issues');" target="_blank" rel="nofollow">反馈</a>
      </li>
    </ul>
  </div>
</div>
 
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
  <div class="layui-side layui-bg-black">
    <div class="layui-side-scroll">
      
<ul class="layui-nav layui-nav-tree site-demo-nav">
  
  <li class="layui-nav-item layui-nav-itemed">
    <a class="javascript:;" href="javascript:;">演示</a>
    <dl class="layui-nav-child">
      <dd>
        <a href="index.html">调试预览</a>
      </dd>
    </dl>
  </li>
  
  <li class="layui-nav-item layui-nav-itemed">
    <a class="javascript:;" href="javascript:;">布局</a>
    <dl class="layui-nav-child">
      <dd class="">
        <a href="grid.html">栅格</a>
      </dd>
      <dd class="">
        <a href="admin.html">框架</a>
      </dd>
    </dl>
  </li>
  
  <li class="layui-nav-item layui-nav-itemed">
    <a class="javascript:;" href="javascript:;">基本元素</a>
    <dl class="layui-nav-child">
      <dd class="">
        <a href="button.html">按钮</a>
      </dd>
      <dd class="">
        <a href="form.html">表单</a>
      </dd>
      <dd class="">
        <a href="nav.html">导航 / 面包屑</a>
      </dd>
      <dd class="">
        <a href="menu.html">基础菜单</a>
      </dd>
      <dd class="">
        <a href="tab.html">选项卡</a>
      </dd>
      <dd class="">
        <a href="progress.html">进度条</a>
      </dd>
      <dd class="">
        <a href="panel.html">面板</a>
      </dd>
      <dd class="">
        <a href="badge.html">徽章</a>
      </dd>
      <dd class="">
        <a href="timeline.html">时间线</a>
      </dd>
      <dd class="">
        <a href="table-element.html">静态表格</a>
      </dd>
      <dd class="">
        <a href="anim.html">动画</a>
      </dd>
      <dd class="">
        <a href="auxiliar.html">辅助元素</a>
      </dd>
    </dl>
  </li>
  
  <li class="layui-nav-item layui-nav-itemed">
    <a class="javascript:;" href="javascript:;">组件示例</a>
    <dl class="layui-nav-child">
      <dd class="">
        <a href="layer.html">
          弹出层
        </a>
      </dd>
      <dd class="">
        <a href="laydate.html">
          日期与时间选择
        </a>
      </dd>
      <dd class="">
        <a href="table.html">
          数据表格
        </a>
      </dd>
       <dd class="">
        <a href="laypage.html">
          分页
        </a>
      </dd>
      <dd class="">
        <a href="dropdown.html">
          下拉菜单
        </a>
      </dd>
      <dd class="">
        <a href="upload.html">
          文件上传
        </a>
      </dd>  
      <dd class="">
        <a href="transfer.html">
          穿梭框
        </a>
      </dd>
      
       <dd class="">
        <a href="tree.html">
          树形组件
        </a>
      </dd>
      <dd class="layui-this">
        <a href="">
          颜色选择器
        </a>
      </dd>
      <dd class="">
        <a href="slider.html">
          滑块
        </a>
      </dd>
      <dd class="">
        <a href="rate.html">
          评分
        </a>
      </dd>
      <dd class="">
        <a href="carousel.html">
          轮播
        </a>
      </dd>
      <dd class="">
        <a href="laytpl.html">
          模板引擎
        </a>
      </dd>
      <dd class="">
        <a href="flow.html">
          流加载
        </a>
      </dd>
      <dd class="">
        <a href="util.html">
          工具模块
        </a>
      </dd>
      <dd class="">
        <a href="code.html">
          文本行修饰
        </a>
      </dd>
    </dl>
  </li>
  
  <li class="layui-nav-item" style="height: 30px; text-align: center"></li>
</ul>

    </div>
  </div>
  <div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
    <ul class="layui-tab-title site-demo-title">
      <li class="layui-this">预览</li>
      <li>查看代码</li>
      <li>帮助</li>
    </ul>
    <div class="layui-body layui-tab-content site-demo site-demo-body">
    
    
      <div class="layui-tab-item layui-show">
        <div class="layui-main">
          <div id="LAY_preview">
            
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>常规使用</legend>
</fieldset>
 
<div style="margin-left: 30px;">
  <div id="test1"></div>
  <div id="test2" style="margin-left: 30px;"></div>
</div>
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>表单赋值</legend>
</fieldset>
 
<div style="margin-left: 30px;">
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <div class="layui-input-inline" style="width: 120px;">
        <input type="text" value="" placeholder="请选择颜色" class="layui-input" id="test-form-input">
      </div>
      <div class="layui-inline" style="left: -11px;">
        <div id="test-form"></div>
      </div>
    </div>
  </form>
</div>
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>RGB / RGBA 色值</legend>
</fieldset>
<div style="margin-left: 30px;">
  <div id="test3"></div>
  <div id="test4" style="margin-left: 30px;"></div>
</div>
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>透明度选择</legend>
</fieldset>
 
<div style="margin-left: 30px;">
  <div id="test5"></div>
  <div id="test6" style="margin-left: 30px;"></div>
  <div id="test7" style="margin-left: 30px;"></div>
</div>
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>预定义颜色项</legend>
</fieldset>
 
<div style="margin-left: 30px;">
  <div id="test8"></div>
  <div id="test9" style="margin-left: 30px;"></div>
</div>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>全功能和回调的使用</legend>
</fieldset>
<div style="margin-left: 30px;">
  <input type="hidden" name="color" value="" id="test-all-input">
  <div id="test-all"></div>
</div>
 
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
  <legend>颜色框尺寸</legend>
</fieldset>
 
<div style="margin-left: 30px;">
  <div id="test10"></div>
  <div id="test11" style="margin-left: 30px;"></div>
  <div id="test12" style="margin-left: 30px;"></div>
</div>
            
          </div>
          
<blockquote class="layui-elem-quote" style="margin-top: 30px;">
  更多我们未能呈现的示例，还有待您在阅读文档、以及不断使用的过程，去深入挖掘。
</blockquote>
<div style="margin: 15px 0 100px; padding-bottom: 100px;">
  <!-- 通用-970*90 -->
  <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="6835627838"></ins>
</div>
        </div>
      </div>
      
      
      <div class="layui-tab-item">
<textarea class="layui-border-box site-demo-text site-demo-code" id="LAY_democode" spellcheck="false" readonly="">
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="//res.layui.com/layui/dist/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
</textarea>
      </div>
      
      
      <div class="layui-tab-item">
        <div class="layui-main">
          <p></p>
          
          
          
          <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
            <legend>相关</legend>
          </fieldset>
          <a class="layui-btn layui-btn-normal" href="../doc/modules/colorpicker.html" target="_blank">颜色选择器文档</a>
        </div>
      </div>
      
        
    </div>
  </div>
  
<div class="layui-footer footer footer-demo">
    <p>
      Copyright &copy; 2021 <a href="../index.html">layui.com</a> MIT Licensed</p>
    <p>
      <a href="../about/disclaimer.html" target="_blank">免责声明</a> 
      <a href="../about/relatedlinks.html" target="_blank">友链</a>
      <a href="javascript:;" site-event="weixinmp">公众号</a>
      <a target="_blank" href="javascript:window.open('http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=36010902000274');" rel="nofollow">
        <img src="../upload/2021_8/168_1628847893037_87773.png">
        赣公网安备 36010902000274号
      </a>
      <a href="javascript:window.open('https://beian.miit.gov.cn/');" target="_blank" rel="nofollow">赣ICP备13006272号</a>
    </p>
    <div class="site-union">
      <p class="site-union-desc">
        <span>
          
        </span>
      </p>
      <p>    
        <a href="javascript:window.open('https://console.upyun.com/register/?invite=SJ0wu6g2-');" target="_blank" rel="nofollow" sponsor="upyun">
          <img src="../static/images/other/upyun.png" alt="upyun">
        </a>    
        <a href="javascript:window.open('https://www.maoyun.com/?from=layui');" target="_blank" rel="nofollow" sponsor="maoyun">
          <img src="../upload/2019_5/168_1559291577683_9348.png" alt="maoyun">
        </a>
      </p>
    </div>
</div>
<script>
window.global = {
  pageType: 'demo'
  ,preview: function(){
    var preview = document.getElementById('LAY_preview');
    return preview ? preview.innerHTML : '';
  }()
};
</script>
<script async="" src="../pagead/js/adsbygoogle.js"></script>
<div class="site-tree-mobile layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
<div class="site-mobile-shade"></div>
 
<script src="../layui/dist/layui.js" ></script>
<script>
layui.config({
  base: '../../static/lay/modules/layui/'
  ,version: '1632428048260'
}).use('global');
</script>
 
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?d214947968792b839fd669a4decaaffc";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<div id="LAY_democodejs">
<script>
layui.use('colorpicker', function(){
  var $ = layui.$
  ,colorpicker = layui.colorpicker;
  //常规使用
  colorpicker.render({
    elem: '#test1' //绑定元素
    ,change: function(color){ //颜色改变的回调
      layer.tips('选择了：'+ color, this.elem, {
        tips: 1
      });
    }
  });
   
  //初始色值
  colorpicker.render({
    elem: '#test2'
    ,color: '#2ec770' //设置默认色
    ,done: function(color){
      layer.tips('选择了：'+ color, this.elem);
    }
  });
  
  //表单赋值
  colorpicker.render({
    elem: '#test-form'
    ,color: '#1c97f5'
    ,done: function(color){
      $('#test-form-input').val(color);
    }
  });
  
  //RGB 、RGBA
  colorpicker.render({
    elem: '#test3'
    ,color: 'rgb(68,66,66)'
    ,format: 'rgb' //默认为 hex
  });
  colorpicker.render({
    elem: '#test4'
    ,color: 'rgba(68,66,66,0.5)'
    ,format: 'rgb'
    ,alpha: true //开启透明度滑块
  });
  
  //开启透明度
  colorpicker.render({
    elem: '#test5'
    ,color: '#009688' //hex
    ,alpha: true //开启透明度
    ,format: 'rgb'
  });
  colorpicker.render({
    elem: '#test6'
    ,color: 'rgb(0,150,136,0.6)' //rgba
    ,alpha: true
    ,format: 'rgb'
  });
  colorpicker.render({ //无初始色值时
    elem: '#test7'
    ,alpha: true
    ,format: 'rgb'
  });
  
  //预定义颜色项
  colorpicker.render({
    elem: '#test8'
    ,color: '#c71585'
    ,predefine: true // 开启预定义颜色
  });
  colorpicker.render({
    elem: '#test9'
    ,color: '#9d8a0e'
    ,predefine: true // 开启预定义颜色
    ,colors: ['#ff8c00','#00ced1','#9d8a0e'] //自定义预定义颜色项
  });
  
  //开启全功能
  colorpicker.render({
    elem: '#test-all'
    ,color: 'rgba(7, 155, 140, 1)'
    ,format: 'rgb'
    ,predefine: true
    ,alpha: true
    ,done: function(color){
      $('#test-all-input').val(color); //向隐藏域赋值
      layer.tips('给指定隐藏域设置了颜色值：'+ color, this.elem);
      
      color || this.change(color); //清空时执行 change
    }
    ,change: function(color){
      //给当前页面头部和左侧设置主题色
      $('.header-demo,.layui-side .layui-nav').css('background-color', color);
    }
  });
  
  //设定颜色框尺寸
  colorpicker.render({
    elem: '#test10'
    ,size: 'lg' //大号下拉框
  });
  colorpicker.render({
    elem: '#test11'
    //,size: 'sm' //默认 sm
  });
  colorpicker.render({
    elem: '#test12'
    ,size: 'xs' //mini下拉框
  });  
});
</script>
</div>
</body>
</html>